var _m_url = window.parent._index_path;


function initRQuery(divName,reId,title,config,specialConfig){
	_loadColumnAjaxR(reId,'4',reId,divName,title,config,'','',specialConfig);
}


//function authformatter (){}
//function opformatter (){}
//function stformatter (){}


/***
 * 当点击通用的统计筛选条件时会触发的事件
 * @param obj
 * @return
 */
function repertory(obj){
	var dsId = $(obj).attr('dsid');  //dsId
	var config=$(obj).attr("name"); //筛选条件
	$("a[name="+config+"] input[name=viewCon]").attr("checked",true)
	var title=$(obj).attr("title");
	$.ajax({
		type:'post',
		url:_m_url+'report/loadListData',
		data:{'dsId':dsId,'type':4},
		success:function(data){
			initRQuery('report_DATALIST',dsId,title,config,'');
		}
	});
}

/***
 * 当点击批销退货统计筛选条件时会触发的事件
 * @param obj
 * @return
 */
function returngoods(obj){
	var dsId = $(obj).attr('dsid');  
	var newDsId=$(obj).attr("name"); 
	$("a[name="+newDsId+"] input[name=viewCon]").attr("checked",true)
	var title=$(obj).attr("title");
	$.ajax({
		type:'post',
		url:_m_url+'report/loadListData',
		data:{'dsId':dsId,'type':4},
		success:function(data){
			initRQuery('report_DATALIST',newDsId,title,'','');
		}
	});
}

/**********************************************************************************
 * 动态加载字段的方法封装开始  
    type：4 列表结果界面
 ********************************************************/
function _loadColumnAjaxR(dsId,type,reId,divName,title,config,cbfn,keyValues,specialConfig){
	//如果没有加载筛选条件
	if(config==''){
		$.ajax({
			type:'post',
			url:_m_url+'report/loadColumns',
			data:{'dsId':dsId,'type':4},
			success:function(data){
				if(data ==""){
					alert("数据为空");
				}else{
					producePage(data,divName,'4','');    //加载列
					if(cbfn != ""){
					eval(cbfn).call(this,data,dsId,dsId,keyValues);
					}
					_f_bquery(dsId,dsId,divName,title,config,specialConfig);    //加载列表的数据
				}
			}
		});
	}else{
		//加了筛选条件
		$.ajax({
			type:'post',
			url:_m_url+'report/getViewCols',
			data:{'dsId':dsId,"config":config,'type':4},
			success:function(data){
				if(data ==""){
					alert("数据为空");
				}else{
					producePage(data,divName,type,'');    //加载列
					if(cbfn != ""){
						eval(cbfn).call(this,data,dsId,dsId,keyValues);
					}
					_f_bquery(dsId,dsId,divName,title,config,specialConfig);    //加载列表的数据
				}
			}
		});
	}
}


function _f_bquery(prefix,dsId,divName,title,config,specialConfig){
	var tabId = 'costTabPanel';
	_f_squery(prefix,dsId,tabId,divName,title,config,specialConfig);
}

//需要拼接的语句   显示条件的id  标签的id 标签的title 结果填充的Dg
function _f_squery(prefix,dsId,tabId,divName,title,config,specialConfig){
	$('#'+prefix+"_"+tabId).tabs('select',title+'列表');
	//判断是否有统计条件查询
	if(config==''){
		//判断是否有特殊的条件查询
		if(specialConfig!=''){
			$('#'+divName).datagrid({url:_m_url+'report/specialSelect?dsId='+dsId+'&specialConfig='+specialConfig});
		}else{
			$('#'+divName).datagrid({url:_m_url+'report/loadFullData?dsId='+dsId+'&config='+config});
		}
	}else{
		$('#'+divName).datagrid({url:_m_url+'report/loadViewData?dsId='+dsId+'&config='+config});
	}
	
}



/***
 * 自定义的特殊的条查询
 * @param obj
 * @return
 */
function moreSelect(obj){
	/**
	 * 	A!%3D><%3D%3D%2580
		A!=><==%80
	 */
	var dsId = $(obj).attr('dsid');
	var title=$(obj).attr("title");
	var specialConfig='chinese->-80-and;chinese-<%3D-90-or;english-%3D-25-and';
	if($(obj).attr('checked')==true){
		$.ajax({
			type:'post',
			url:_m_url+'report/loadListData',
			data:{'dsId':dsId,'type':4},
			success:function(data){
				initRQuery("report_DATALIST",dsId,title,'',specialConfig);
			}
		});
	}else{
		
	}
}




/***
 * 初始化打印界面
 * @param dsId
 * @param type
 * @param keyValues
 * @param prefix
 * @param pdivName
 * @param divName
 * @return
 */
function initPrint(dsId,type,keyValues,prefix,pdivName,divName){
   	$.parser.parse('#'+prefix+'_P_Div');
	$.ajax({
		type:'post',
		url:_m_url+'printPages/loadColumnsU',   //加载打印的详情页面的条件界面字段
		data:{'dsId':dsId,'type':type,'flag':'2'},
		success:function(data){
			if(data ==""){
				alert("数据为空");
			}else{
				var typeT = new Array();
				typeT = type.split(";");
				divNameT = divName.split(";");
				for(var i = 0; i < typeT.length; i++){
					producePage(data[i],prefix+"_"+divNameT[i],typeT[i],'');
				}
				$.ajax({
					type:'post',
					url:_m_url+'printPages/sinfoData',
					data:{'dsId':dsId,'keyValues':keyValues},
					success:function(dateRow){
						verify = dateRow.queryRow[0].IS_VERIFY;
						//加载下拉框
						$.ajax({
							url:_m_url+'dz/queryDzList',
							type:'post',
							data:{dzIds:serializeEDIType(pdivName)},
							success:function(data){
								fillPrintForm(pdivName,dateRow.queryRow[0]);
							}
						});
					}
				});
			}
		}
	});
}






